const path = require("path");
const express = require("express");

const app = express();
const api = require("./router");

app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.set("view engine", "ejs");
app.set("views", path.join(__dirname, "views"));
app.use("/static", express.static("static"));

// 设置路由
app.use("/api", api);
// 设置页面
app.use("/form", (req, res) => {
    res.render("form");
});
app.use("/jquery", (req, res) => {
    res.render("jquery");
});
app.use("/axios", (req, res) => {
    res.render("axios");
});

// 错误中间件
app.use((err, req, res, next) => {
    res.send({
        code: 500,
        message: "上传失败",
    });
});

app.listen(3000, () => {
    console.log("Server is running on port 3000");
});
